package org.rc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.rc.dto.LawPageDto;
import org.rc.entity.Law;
import org.rc.mapper.LawLibraryMapper;
import org.rc.service.LawLibraryService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LawLibraryServiceImpl extends ServiceImpl<LawLibraryMapper, Law> implements LawLibraryService {

    @Override
    public void removeAllRecords() {
        this.remove(new QueryWrapper<>());
    }

    @Override
    public void addLawLibrary(List<Law> laws) {
        this.saveBatch(laws);
    }

    @Override
    public List<Law> getLaws() {
        return list();
    }

    @Override
    public Page<Law> getLawPage(LawPageDto lawPageDto) {
        Page<Law> page = new Page<>(lawPageDto.getPageNo(),lawPageDto.getPageSize());
        QueryWrapper<Law> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(lawPageDto.getName()),"charge",lawPageDto.getName());
        return this.baseMapper.selectPage(page,queryWrapper);
    }
}
